package bt.servlet.empresa;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bt.dao.EmpresaDAO;
import bt.excepcion.DAOExcepcion;
import bt.modelo.Empresa;

/**
 * Servlet implementation class EmpresaModificarServlet
 */
@WebServlet("/EmpresaModificarServlet")
public class EmpresaModificarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EmpresaModificarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String a = request.getParameter("razonSocial");
		String b = request.getParameter("direccion");
		String c = request.getParameter("cmbPais");
		String d = request.getParameter("cmbDepa");
		String e = request.getParameter("cmbRubro");
		String f = request.getParameter("contacto");
		String g = request.getParameter("correo");
		String h = request.getParameter("sector");
		String i = request.getParameter("ruc");
		String j = request.getParameter("clave");
		
		int ic = Integer.parseInt(c);
		int id = Integer.parseInt(d);
		int ie = Integer.parseInt(e);
		
		System.out.println("Pais: " + ic);
		System.out.println("Depa: " + id);
		System.out.println("Rubro: " + ie);
		
		Empresa vo = new Empresa();
		vo.setRazonsocial(a);
		vo.setDireccion(b);
		vo.setIdPais(ic);
		vo.setIdDepartamento(id);
		vo.setIdRubro(ie);
		vo.setContacto(f);
		vo.setEmailcontacto(g);
		vo.setSector(h);
		vo.setRuc(i);
		vo.setPassword(j);
		vo.setEstado(1);

		EmpresaDAO dao = new EmpresaDAO();
		try {
			dao.actualizar(vo);
			response.sendRedirect(request.getContextPath()
					+ "/empModificado.jsp");
		} catch (DAOExcepcion ex) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
